package edu.tyut.game.ui.user.register

import android.os.CountDownTimer
import android.widget.Button
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.map
import androidx.lifecycle.switchMap
import edu.tyut.game.R
import edu.tyut.game.logic.MailRepository
import edu.tyut.game.logic.UserRepository
import edu.tyut.game.logic.model.User
import edu.tyut.game.utils.LogUtils

class RegisterViewModel : ViewModel() {

    private val tag = "RegisterViewHolder"

    // 是否存该用户
    private val existUserLiveDate = MutableLiveData<User>()
    val existUser = existUserLiveDate.switchMap {
        UserRepository.isExistsUserWeb(it)
    }
    fun isExistUser(user: User){
        existUserLiveDate.value = user
    }

    // 用用户登录
    private val registerLiveData = MutableLiveData<User>()
    var username = ""
    var password = ""
    var confirmPassword = ""
    var email = ""
    var verificationCode = ""
    val registerUser = registerLiveData.switchMap {
        val register = UserRepository.registerWeb(it)
        register
    }
    fun register(user: User){
        registerLiveData.value = user
    }

    // 邮件发送
    private val sendMailLiveData = MutableLiveData<User>()
    val sendMailData = sendMailLiveData.switchMap {
        MailRepository.sendMail(it)
    }
    fun sendMail(user: User){
        sendMailLiveData.value = user
    }

}
// 张书豪
// shuhao1.zhang@tcl.com